import 'package:flutter/material.dart';
import '../routers/application.dart';
import 'package:shared_preferences/shared_preferences.dart';

class MyPage extends StatefulWidget{
    @override
    _MyPageState createState() => _MyPageState();
}

class _MyPageState extends State<MyPage>{
    @override
    Widget build(BuildContext context){
        return Scaffold(
            appBar: AppBar(
                automaticallyImplyLeading: false,
                title: Text("功能开发中"),
            ),
            // body: Container(
            //     width: double.infinity,
            //     height: double.infinity,
            //     child: Image.asset(
            //         "image/temp3.jpg",
            //         fit: BoxFit.fill,
            //     ),
            // ),
            body: Container(
                child: Column(
                    children: <Widget>[
                        FlatButton(
                            color: Colors.yellow,
                            padding: EdgeInsets.fromLTRB(80.0, 15.0, 80.0, 15.0),
                            shape:RoundedRectangleBorder(borderRadius: BorderRadius.circular(20.0)),
                            child: Text("清除token,路由到login页"),
                            onPressed: _loginOut,
                        ),
                        // FlatButton(
                        //     color: Colors.yellow,
                        //     padding: EdgeInsets.fromLTRB(80.0, 15.0, 80.0, 15.0),
                        //     shape:RoundedRectangleBorder(borderRadius: BorderRadius.circular(20.0)),
                        //     child: Text("跳转到测试页面"),
                        //     onPressed: (){
                        //         Application.router.navigateTo(context, "/test");
                        //     },
                        // )
                    ],
                ),
            ),
        );
    }

    void _loginOut() async{
    //4、销毁的方法
        // SharedPreferences prefs =await SharedPreferences.getInstance();
        // prefs.remove("loginToken");

        Future<dynamic> future = Future(()async{
            SharedPreferences prefs =await SharedPreferences.getInstance();
            prefs.remove("loginToken");
        });
        future.then((val){
            print("跳转到首页");
            Application.router.navigateTo(context,"/login");
        }).catchError((e){
            print(e);
        });
    }
}